
open Graphics
open Tools

let width = 500
let height= 500

let rec trace_path trace =
  match trace with
  | []      -> ()
  |(x,y)::q -> 
    print_endline ("dz");
    flush_all;
    lineto 
      ((int_of_float x)+width/2) 
      ((int_of_float y)+height/2);
    trace_path q

let init_set w h =
  open_graph (Printf.sprintf " %dx%d" w h);
  set_window_title "SUPa CL TURTLE";
  set_color black;
  moveto (w/2) (h/2)

let test_ast = Prog_ast([Move_ast(Num_ast(100.))])

let main () =
  init_set width height ;
  while true do
    let lexbuf = (Lexing.from_channel stdin) in
    ignore(eval_turtle_ast (Turtle.prog Lexer.token lexbuf));
    trace_path !turtle_trace      
  done

let _ = main ()
